package com.jmx;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

public class JmsClientDemo {

	public static void main(String[] args) throws Exception {
		JMXServiceURL address = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1234/jmxrmi");
		JMXConnector connector = JMXConnectorFactory.connect(address);
		MBeanServerConnection mbsc = connector.getMBeanServerConnection();
		connector.connect();
		ObjectName objectName = new ObjectName("hello:name=hello");
		if (!mbsc.isRegistered(objectName)) {
			mbsc.createMBean("com.rmi.HelloWorld", objectName, null, null);
		}
		// hello对象属于远程的对象，调用sayHello方法，则是调用服务器端的sayHello方法
//		final HelloWorldMBean hello = JMX.newMBeanProxy(mbsc, objectName, HelloWorldMBean.class);
//		hello.sayHello();
//		System.out.println("\nMBean count = " + mbsc.getMBeanCount());
//		System.out.println("end");

	}

}
